import { SendUserExternals } from './sendUserExternal';
let _SendUserExternals = SendUserExternals;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import SendUserExternalMock from './mdp/arc/send/sendUserExternalMock';
 * SendUserExternalMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mdp/arc/send/sendUserExternal/listKey').reply(config => {
      let params = config.params;
      let mockSendUserExternals = _SendUserExternals.filter(sendUserExternal => {
      	if(params.id||params.id==''){ if( sendUserExternal.id.indexOf(params.id)>=0) return true;}
      	if(params.archiveId||params.archiveId==''){ if( sendUserExternal.archiveId.indexOf(params.archiveId)>=0) return true;}
      	if(params.userid||params.userid==''){ if( sendUserExternal.userid.indexOf(params.userid)>=0) return true;}
      	if(params.remark||params.remark==''){ if( sendUserExternal.remark.indexOf(params.remark)>=0) return true;}
      	if(params.isGet||params.isGet==''){ if( sendUserExternal.isGet.indexOf(params.isGet)>=0) return true;}
      	if(params.replyTime||params.replyTime==''){ if( sendUserExternal.replyTime.indexOf(params.replyTime)>=0) return true;}
      	if(params.createDate||params.createDate==''){ if( sendUserExternal.createDate.indexOf(params.createDate)>=0) return true;}
      	if(params.sendDate||params.sendDate==''){ if( sendUserExternal.sendDate.indexOf(params.sendDate)>=0) return true;}
      	if(params.archiveSendId||params.archiveSendId==''){ if( sendUserExternal.archiveSendId.indexOf(params.archiveSendId)>=0) return true;}
      	if(params.isSendSuccess||params.isSendSuccess==''){ if( sendUserExternal.isSendSuccess.indexOf(params.isSendSuccess)>=0) return true;}
      	if(params.replyMsg||params.replyMsg==''){ if( sendUserExternal.replyMsg.indexOf(params.replyMsg)>=0) return true;}
      	if(params.username||params.username==''){ if( sendUserExternal.username.indexOf(params.username)>=0) return true;}
      	if(params.email||params.email==''){ if( sendUserExternal.email.indexOf(params.email)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockSendUserExternals
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mdp/arc/send/sendUserExternal/list').reply(config => {
      let params = config.params;
      let mockSendUserExternals = _SendUserExternals.filter(sendUserExternal => {
      	var isTrue=false;
      	if(params.id||params.id==''){if(sendUserExternal.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.archiveId||params.archiveId==''){if(sendUserExternal.archiveId.indexOf(params.archiveId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.userid||params.userid==''){if(sendUserExternal.userid.indexOf(params.userid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.remark||params.remark==''){if(sendUserExternal.remark.indexOf(params.remark)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isGet||params.isGet==''){if(sendUserExternal.isGet.indexOf(params.isGet)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.replyTime||params.replyTime==''){if(sendUserExternal.replyTime.indexOf(params.replyTime)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.createDate||params.createDate==''){if(sendUserExternal.createDate.indexOf(params.createDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.sendDate||params.sendDate==''){if(sendUserExternal.sendDate.indexOf(params.sendDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.archiveSendId||params.archiveSendId==''){if(sendUserExternal.archiveSendId.indexOf(params.archiveSendId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendSuccess||params.isSendSuccess==''){if(sendUserExternal.isSendSuccess.indexOf(params.isSendSuccess)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.replyMsg||params.replyMsg==''){if(sendUserExternal.replyMsg.indexOf(params.replyMsg)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.username||params.username==''){if(sendUserExternal.username.indexOf(params.username)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.email||params.email==''){if(sendUserExternal.email.indexOf(params.email)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockSendUserExternals
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockSendUserExternals.length;
      mockSendUserExternals = mockSendUserExternals.filter((sendUserExternal, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockSendUserExternals,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mdp/arc/send/sendUserExternal/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _SendUserExternals = _SendUserExternals.filter(sendUserExternal => sendUserExternal.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mdp/arc/send/sendUserExternal/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _SendUserExternals = _SendUserExternals.filter(sendUserExternal => !params.includes(sendUserExternal.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mdp/arc/send/sendUserExternal/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { id,archiveId,userid,remark,isGet,replyTime,createDate,sendDate,archiveSendId,isSendSuccess,replyMsg,username,email } = params;
      _SendUserExternals.some(sendUserExternal => {
        if (sendUserExternal.id === id) {
			sendUserExternal.id = id;
			sendUserExternal.archiveId = archiveId;
			sendUserExternal.userid = userid;
			sendUserExternal.remark = remark;
			sendUserExternal.isGet = isGet;
			sendUserExternal.replyTime = replyTime;
			sendUserExternal.createDate = createDate;
			sendUserExternal.sendDate = sendDate;
			sendUserExternal.archiveSendId = archiveSendId;
			sendUserExternal.isSendSuccess = isSendSuccess;
			sendUserExternal.replyMsg = replyMsg;
			sendUserExternal.username = username;
			sendUserExternal.email = email
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mdp/arc/send/sendUserExternal/add').reply(config => {
      var params = JSON.parse( config.data );
      let { id,archiveId,userid,remark,isGet,replyTime,createDate,sendDate,archiveSendId,isSendSuccess,replyMsg,username,email } = params;
      _SendUserExternals.push({
		id:id,
		archiveId:archiveId,
		userid:userid,
		remark:remark,
		isGet:isGet,
		replyTime:replyTime,
		createDate:createDate,
		sendDate:sendDate,
		archiveSendId:archiveSendId,
		isSendSuccess:isSendSuccess,
		replyMsg:replyMsg,
		username:username,
		email:email
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};